package com.hippomeetsskunk.savanna.types.resource;

import java.util.List;
import java.util.Set;

import org.apache.log4j.Logger;

import com.hippomeetsskunk.savanna.model.ModelProvider;
import com.hippomeetsskunk.savanna.types.meta.ResourceType;
import com.hippomeetsskunk.savanna.types.meta.SimObjectType;
import com.hippomeetsskunk.savanna.types.person.Skills;
import com.hippomeetsskunk.savanna.types.world.Region;
import com.hippomeetsskunk.savanna.types.world.Time;

public class Resource extends AbstractSimObject implements RelocatableObject{

	private static Logger logger = Logger.getLogger(Resource.class);
		
	public Resource(SimObjectType type, double value, double quality) {
		super(type, value, quality);
	}

	public Resource(String name, SimObjectType type, double value, double quality) {
		super(name, type, value, quality);
	}

	public Set<ResourceType> getResourcesForImprovement() {
		return getType().getResourcesForImprovement();
	}

	public Skills getSkillsForImprovement() {
		return getType().getSkillsForImprovement();
	}

	public void improve(double work, List<RelocatableObject> resources) {
		// TODO check and consume resources
		setQuality(ModelProvider.getInstance().getQualityModel().improve(getQuality(), getType().getDifficulty(), work));
		logger.debug(this + " improved to " + getQuality());
	}

	public void startDay(Time time, Region region) {
		setQuality(ModelProvider.getInstance().getDecayModel().calculateQualityDecay(getType().getLifeTime(), getType().getFragility(), getQuality(), 1.0));
		logger.debug(this + " decay to " + getQuality());
	}

	@Override
	public ResourceType getType() {
		return (ResourceType) super.getType();
	}

	
}
